﻿using IDAdmin.Common;
using IDAdmin.Lib.DataLayer;
using IDAdmin.Lib.UI;
using IDAdmin.Lib.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IDAdmin.Pages
{
    public partial class RatioDetails : BasePage
    {
        public RatioDetails()
            : base(Lib.AppFunctions.RATUODETAILS)
        {

        }
        protected override void Page_Load(object sender, EventArgs e)
        {
            try {
                if (!IsLogin())
                {
                    RedirectToLogOn();
                }
                else if (!CheckRight())
                {
                    RedirectToDeniedMessage();
                }
                if (IsPostBack)
                {
                    RatioGosu R = new RatioGosu();
                    R.gosu = Convert.ToInt32(gosuTextBox1.Text);
                    R.ratio = radioTextBox1.Text;
                    R.phieudiem = Convert.ToInt32(phieudiemTextBox2.Text);
                    R.id = Request.QueryString["id"] != null ? Request.QueryString["id"] : "0";
                    bool status = WebDB_N.SaveRatio(R);
                    if (status == true)
                    {
                        messLabel4.Text = "Thành công";
                    }
                    else
                    {
                        messLabel4.Text = "Thất bại, vui lòng thử lại!";
                    }
                }
                string id = Request.QueryString["id"];
                if (id != null)
                {
                    RatioGosu R = WebDB_N.getListRatioBy(Convert.ToInt32 (id));
                    gosuTextBox1.Text = R.gosu.ToString();
                    radioTextBox1.Text = R.ratio;
                    phieudiemTextBox2.Text = R.phieudiem.ToString();     
                }
                                         
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void saveButton1_Click(object sender, EventArgs e)
        {
            try
            {
                string id = Request.QueryString["id"];
                if (id != null)
                {
                    RatioGosu R = WebDB_N.getListRatioBy(Convert.ToInt32(id));
                    gosuTextBox1.Text = R.gosu.ToString();
                    radioTextBox1.Text = R.ratio;
                    phieudiemTextBox2.Text = R.phieudiem.ToString();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}